<template>
    <div class="goods-list">
       <div class="goods-item" v-for="item in goodslist" :key="item.id">
           <img :src="item.img_url" alt="">
           <h1 class="title">{{ item.title }}</h1>
           <div class="info">
               <p class="price">
                   <span class="now">￥{{ item.sell_price }}</span>
                   <span class="old">￥{{ item.market_price }}</span>
               </p>
               <p class="sell">
                   <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
               </p>
           </div>
       </div>


       <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
 export default {
     data() {
         return {
             pageindex:1,
             goodslist: []
         };
     },
     created() {
         this.getGoodsList();
     },
     methods: {
         getGoodsList() {
             for ( var i=0; i<5; i++ ) {
                    var itemId = (this.pageIndex*10 + i).toString();
                    // console.log(itemId);
                    var item = {
                        add_time: "2015-01-16T03:50:28.000Z",
                        click:34,
                        title: "小米（Mi）小米Note 16G双网通版",
                        zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                        img_url:
                        "http://img5.imgtn.bdimg.com/it/u=1894439638,1380559699&fm=26&gp=0.jpg",
                        sell_price: 2199,
                        market_price: 2399,
                        stock_quantity: 200
                        };
                        this.goodslist.push(item);
             }
             var body = {
                status: 0,
                // message: [
                //      {
                //     id:111,
                //     add_time: "2015-01-16T03:50:28.000Z",
                //     click:34,
                //     title: "小米（Mi）小米Note 16G双网通版",
                //     zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                //     img_url:
                //     "http://img5.imgtn.bdimg.com/it/u=1894439638,1380559699&fm=26&gp=0.jpg",
                //     sell_price: 2199,
                //     market_price: 2399,
                //     stock_quantity: 200
                //     },
                //     {
                //     id: 112,
                //     add_time: "2015-02-16T03:50:28.000Z",
                //     click:34,
                //     title: "小米（Mi）小米Note 16G双网通版",
                //     zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                //     img_url:
                //     "http://img4.imgtn.bdimg.com/it/u=4121670377,1478679261&fm=11&gp=0.jpg",
                //     sell_price: 2199,
                //     market_price: 2399,
                //     stock_quantity: 200
                //     },
                //     {
                //     id: 113,
                //     add_time: "2015-03-16T03:50:28.000Z",
                //     click:34,
                //     title: "小米（Mi）小米Note 16G双网通版",
                //     zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                //     img_url:
                //     "http://img4.imgtn.bdimg.com/it/u=1676399440,479155800&fm=26&gp=0.jpg",
                //     sell_price: 2199,
                //     market_price: 2399,
                //     stock_quantity: 200
                //     },
                //     {
                //     id: 114,
                //     add_time: "2015-04-16T03:50:28.000Z",
                //     click:34,
                //     title: "小米（Mi）小米Note 16G双网通版",
                //     zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                //     img_url:
                //     "http://img4.imgtn.bdimg.com/it/u=7832913,494616907&fm=26&gp=0.jpg",
                //     sell_price: 2199,
                //     market_price: 2399,
                //     stock_quantity: 200
                //     },
                //     {
                //     id: 115,
                //     add_time: "2015-05-16T03:50:28.000Z",
                //     click:34,
                //     title: "小米（Mi）小米Note 16G双网通版",
                //     zhaiyao: "后台很多小伙伴给我发私信说公众号上面试题刷不了了，因为之前系统迁移导致数据丢失s",
                //     img_url:
                //     "http://img4.imgtn.bdimg.com/it/u=833187437,2571811097&fm=26&gp=0.jpg",
                //     sell_price: 2199,
                //     market_price: 2399,
                //     stock_quantity: 200
                //     }
                // ]
                
             };
             if(body.status == 0) {
                 //this.goodslist = body.message
                 //this.goodslist = this.goodslist.concat(body.message);
             }
        
         },
     getMore() {
             this.pageindex++;
             this.getGoodsList();
     }  
 }   
 }
</script>



<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  justify-content: space-between;
  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    min-height: 293px;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-size: 16px;
          font-weight: bold;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}
</style>
